package com.http;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;
import com.modle.User;
import com.util.UserUtil;

/**
 * 
 * @ClassName://发到朋友圈
 * @Description://
 * @author zhuw
 * @date 2013-8-22 下午8:50:26
 */
public class RemovePyqTask extends AsyncTask<Object, Void, ResultString> {
	public static interface CallBack extends NetWorkCallBack {
		/**
		 * 
		 * @Description:TODO搜索用户信息
		 * @param@param data
		 * @return void
		 * @author zhuw
		 * @date 2013-8-22 下午8:50:36
		 */
		public abstract void removePyq(String result);

	}

	CallBack callback;

	public RemovePyqTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultString doInBackground(Object... params) {
		ResultString data = null;
		try {
			String uid = "";
			User user = UserUtil.readUser();
			if (user != null) {
				uid = user.id;
			}
			HashMap<String, Object> map = (HashMap<String, Object>)params[0];
			ArrayList<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
			if (map != null && !map.isEmpty()) {
				for (Map.Entry<String, Object> entry : map.entrySet()) {
							paramPairs.add(new BasicNameValuePair(entry.getKey(),
									entry.getValue().toString()));
				}
			}
			ResEntity re=NetConUtil.postByForm(ServerPath.REMOVE_TO_PYQ,paramPairs);
			if(re.code==ResEntity.S_OK){
			   // data= new ResultUserList(CommonData.H_FLAG_SUCCESS, null, JsonUtil.parseUserList(new JSONArray(re.jsonStr)));
				data= new ResultString(CommonData.H_FLAG_SUCCESS, null, re.jsonStr);
			}else if(re.code==ResEntity.S_FAILED){
				data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
				// data= new ResultUserList(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+re.jsonStr, null);
				
			}else{
				data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
				 // data= new ResultUserList(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data = new ResultString(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			//data= new ResultUserList(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	protected void onPostExecute(ResultString result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.removePyq(result.result);

		} else {
			callback.procError(result.msg);
		}

	}
}
